using System.Collections.Generic;
using System.Web.UI.WebControls;
using ValidationFramework.Reflection;

namespace ValidationFramework.Web.ASP
{
    public class RequiredStringRuleClientValidationGenerator : IClientValidationGenerator
    {


        /// <inheritdoc />
        public IList<BaseValidator> CreateWebClientValidators(Rule rule, InfoDescriptor infoDescriptor)
        {
            var requiredStringRule = (RequiredStringRule) rule;
            var validator = new ExtendedRequiredFieldValidator();
            if (requiredStringRule.InitialValue != null)
            {
                validator.InitialValue = requiredStringRule.InitialValue;
            }
            validator.IgnoreCase = requiredStringRule.IgnoreCase;
            validator.TrimWhiteSpace = requiredStringRule.TrimWhiteSpace;

            return new BaseValidator[] { validator };
        }

        /// <inheritdoc />
        public bool CanHandleTarget(RuleContext ruleContext)
        {
            return ruleContext.Rule is RequiredStringRule;
        }
    }
}